<?php


namespace app\controller;

use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\GetMapping;

#[Controller('/')]
class tool
{
    /**
     * 获取 Live2d Model
     * @param int $model
     * @return Response
     */
    #[GetMapping]
    public function getLive2dModel(int $model = 22): Response {
        $ra1 = rand(1, 12);
        $ra2 = rand(1, 11);

        if ($model === 22) {
            $idle3 = 100;
            $tap1 = 150;
            $tap2 = 100;
        } else {
            $idle3 = 1000;
            $tap1 = 500;
            $tap2 = 200;
        }
        $root = "../static/cms/live2d/model/${model}";
        return json([
            'model' => "$root/$model.v2.moc",
            'textures' => [
                "${root}/textures/texture_00.png",
                "${root}/textures/texture_01/$ra1.png",
                "${root}/textures/texture_02/$ra1.png",
                "${root}/textures/texture_03/$ra2.png"
            ],
            'hit_areas_custom' => [
                "head_x" => [-0.35, 0.6],
                "head_y" => [0.19, -0.2],
                "body_x" => [-0.3, -0.25],
                "body_y" => [0.3, -0.9]
            ],
            'layout' => [
                "center_x" => -0.1,
                "center_y" => 0.0,
                "width" => 2.4,
                "height" => 2.4
            ],
            'motions' => [
                'idle' => [
                    [
                        "file" => "${root}/${model}.v2.idle-01.mtn",
                        "fade_in" => 2000,
                        "fade_out" => 2000
                    ],
                    [
                        "file" => "${root}/${model}.v2.idle-02.mtn",
                        "fade_in" => 2000,
                        "fade_out" => 2000
                    ],
                    [
                        "file" => "${root}/${model}.v2.idle-02.mtn",
                        "fade_in" => $idle3,
                        "fade_out" => $idle3
                    ]
                ]
            ],
            'tap_body' => [
                [
                    "file" => "${root}/${model}.v2.touch.mtn",
                    "fade_in" => $tap1,
                    "fade_out" => $tap2
                ]
            ],
            'thanking' => [
                [
                    'file' => "${root}/${model}.v2.thanking.mtn",
                    'fade_in' => 2000,
                    'fade_out' => 2000
                ]
            ]
        ]);
    }
}